<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicTableCols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsInitTable="true"
      :dynamicIsColumnDrop="true"
    >
      <template slot="controlBtn" slot-scope="scope">
        <el-button
          type="primary"
          size="mini"
          class="el-icon-edit"
          @click="edit(scope.row.index)"
          >编辑</el-button
        >
      </template>
    </one-table-template>
    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :is-show-chooes="isShowChooes"
      @close="close"
    />
  </div>
</template>

<script>
import OneTableTemplate from "@/components/wms/templates/oneTable";
import { basedataApi } from "@/api/wms/basedata";
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import requesta from "../../../../utils/request.js";
export default {
  components: {
    OneTableTemplate,
    Edit: () => import("./edit")
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          position: "right",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query") /*查询*/
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          name: "reset",
          position: "right",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset") /*重置*/
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          name: "add ",
          position: "left",
          clickEvent: () => this.add(),
          text: "新增" /*导出*/
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          name: "add ",
          position: "left",
          clickEvent: () => this.export(),
          text: "导出" /*导出*/
        }
      ],
      tableComponents: [
        {
          compKey: "compKey2",
          labelName: "仓库编码" /*厂商名称*/,
          codeField: "WAREHOUSE_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        // {
        //   compKey: "compKey1",
        //   labelName: "仓库名称",
        //   codeField: "WAREHOUSE_NAME",
        //   component: () => import("@/components/org/dropdownList/dropdownList"),
        //   options: [],
        //   type: "dropdownList",
        //   isMust: true
        // },
        {
          compKey: "editC_compKey1",
          labelName: "仓库名称",
          textField: "WAREHOUSE_NAME",
          codeField: "WAREHOUSE_NAME",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsWarehouse/indexC"),
          type: "propus",
          isMust: true,
          // span: 23,
          // isMul: false,
         
          readonly: false,
          returnCodeField: "WAREHOUSE_NAME",
          returnTextField: "WAREHOUSE_NAME",
          isRequire: false
          // 非必填
        },
        {
          compKey: "compKey6",
          labelName: "状态", // '状态',
          codeField: "IS_ENABLE",
          component: () => import("@/components/wms/isEnable/isEnableOne"),
          type: "dropdownList",
          isMust: true
        }
      ],
      tableCols: this.getCols(),
      //表单查询数据
      formField: {
        WAREHOUSE_CODE: "",
        WAREHOUSE_NAME: "",
        IS_ENABLE: ""
      },
      isShowChooes: false,
      apiConfig: basedataApi.passagewayInfo
    };
  },
  created() {
    this.dropdownList();
  },
  methods: {
    add() {
      // this.isShowChooes = true;
      this.showEdit("add");
    },
    dropdownList() {
      requesta({
        url: "/mp/wm/vl/basedata/warehouse/querywarehouse.do",
        method: "POST",
        headers: {
          "Cache-Control": "no-cache, no-store,max-age=0, must-revalidate",
          Pragma: "no-cache",
          Expires: "0",
          "Content-Type": "application/json;charset=UTF-8"
        },
        data: {}
      }).then(res => {
        res.listResult.rows.map(item => {
          this.tableComponents[1].options.push({
            label: item.WAREHOUSE_NAME,
            value: item.WAREHOUSE_NAME
          });
        });
      });
    },
    export() {
      const exportLoading = this.$loading({
        lock: true,
        text: "正在导出...",
        // spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        fullscreen: true
      });
      requesta({
        url: "/mp/wm/vl/basedata/warehouse/exportwarehouse.do",
        method: "POST",
        headers: {
          "Content-Type": "application/json;charset=UTF-8"
        },
        responseType: "blob",
        data: this.formField
      })
        .then(response => {
          exportLoading.close();
          let blob = new Blob([response], { type: "application/vnd.ms-excel" }); // 这里表示xmlx类型
          let downloadElement = document.createElement("a");
          let href = window.URL.createObjectURL(blob); // 创建下载的链接
          downloadElement.href = href;
          downloadElement.download = "仓库管理.xls"; // 下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); // 点击下载
          document.body.removeChild(downloadElement); // 下载完成移除元素
          window.URL.revokeObjectURL(href); // 释放掉blob对象
        })
        .catch(err => {
          exportLoading.close();
          console.info(err);
        });
    },
    getCols() {
      var cols = [
        {
          prop: "controlBtn",
          label: "操作", //"操作"
          codeField: "controlBtn",
          width: 80,
          align: "center",
          isSlot: true
        }
      ];
      cols = cols.concat([
        {
          prop: "WAREHOUSE_CODE",
          label: "仓库编码",
          width: null,
          align: "center"
        },
        {
          prop: "WAREHOUSE_NAME",
          label: "仓库名称",
          width: null,
          align: "center"
        },
        {
          prop: "WAREHOUSE_ADDR",
          label: "仓库地址",
          width: null,
          align: "center"
        },
        {
          prop: "LINK_MAN",
          label: "联系人",
          width: null,
          align: "center"
        },
        {
          prop: "CANTACTS",
          label: "联系方式",
          width: null,
          align: "center"
        },
        {
          prop: "IS_VIRTUAL_STR",
          label: "是否虚拟库",
          width: null,
          align: "center"
        },
        {
          prop: "IS_CENTRE_STR",
          label: "是否中心库",
          width: null,
          align: "center"
        },
        {
          prop: "CREATED_DATE",
          label: "创建日期",
          width: null,
          align: "center"
        },
        {
          prop: "CREATOR",
          label: "创建人",
          width: null,
          align: "center"
        },
        {
          prop: "IS_ENABLE_STR",
          label: "状态",
          width: null,
          align: "center"
        }
      ]);
      return cols;
    }
  }
};
</script>
